var t = require("../../../mybehaviors/location/location"), a = getApp();

Page({
    behaviors: [ t ],
    data: {
        language: "",
        show1: !1,
        show2: !1,
        show3: !1,
        value: 0,
        valueData: 0,
        date_obj_arr: [],
        start_time: "",
        end_time: "",
        night_day: "",
        carousels_arr: [],
        bannerObj: {},
        catagory_arr: [],
        location: {},
        hotel_arr: [],
        loading: !1,
        allLoaded: !1,
        goload: !0,
        isLoadMore: !0,
        page: 1,
        total_page: 0,
        star_arr: [ {
            name: "二星及以下/经济型",
            value: 2
        }, {
            name: "三星/舒适",
            value: 3
        }, {
            name: "四星/高档",
            value: 4
        }, {
            name: "五星/豪华",
            value: 5
        }, {
            name: "六星",
            value: 6
        }, {
            name: "七星",
            value: 7
        }, {
            name: "八星",
            value: 8
        }, {
            name: "不限",
            value: 0
        } ],
        current_index: 0,
        star_value: 0,
        toolbar: !1,
        PageNameList: {},
        address: "",
        point: {
            lat: "",
            lng: ""
        },
        city: "",
        title: "",
        HOTEL_LIST: "plugin.hotel.frontend.hotel.hotel.get-hotel-list-to-page",
        INDEX_OTHER_URL: "plugin.hotel.frontend.hotel.get-default.get-index-data",
        CATAGORY_URL: "plugin.hotel.frontend.hotel.hotel-category.get-list"
    },
    onLoad: function(t) {
        var a = this;
        if (this.getInitTime(), this.getOtherData(), this.getCatagoryData(), this.getCustomizeHotelHead(), 
        t.addressData) {
            var e = JSON.parse(t.addressData);
            this.setData({
                "point.lat": e.latitude,
                "point.lng": e.longitude,
                address: e.title,
                title: e.title,
                city: e.city
            }), this.getList();
        } else this._getLocation(function() {
            a.getList();
        });
    },
    onReady: function() {
        var t = wx.getStorageSync("langIndex");
        this.setData({
            language: t.en
        });
    },
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.isLoadMore ? this.getMoreList() : console.log("没有更多数据");
    },
    onShareAppMessage: function() {},
    show2btn: function() {
        this.setData({
            show2: !0
        });
    },
    show3btn: function() {
        this.setData({
            show3: !0
        });
    },
    show1btn: function() {
        this.setData({
            show1: !0
        });
    },
    getList: function() {
        var t = this, e = a.getNetAddresss(t.data.HOTEL_LIST);
        e += "&lng=" + this.data.point.lng, e += "&lat=" + this.data.point.lat, e += "&city_name=" + this.data.city, 
        e += "&page=" + this.data.page, a._getNetWork({
            url: e,
            success: function(a) {
                var e = a.data;
                1 == e.result && t.setData({
                    hotel_arr: e.data.data,
                    hotel_total_page: e.data.last_page
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getInitTime: function() {
        var t = new Date(), a = new Date(t.getTime() + 864e5);
        this.setData({
            start_time: "".concat(t.getFullYear(), "-").concat(t.getMonth() + 1 < 10 ? "0".concat(t.getMonth() + 1) : "".concat(t.getMonth() + 1), "-").concat(t.getDate() < 10 ? "0".concat(t.getDate()) : "".concat(t.getDate()))
        }), this.setData({
            end_time: "".concat(a.getFullYear(), "-").concat(a.getMonth() + 1 < 10 ? "0".concat(a.getMonth() + 1) : "".concat(a.getMonth() + 1), "-").concat(a.getDate() < 10 ? "0".concat(a.getDate()) : "".concat(a.getDate()))
        });
    },
    getOtherData: function() {
        var t = this, e = a.getNetAddresss(t.data.INDEX_OTHER_URL);
        a._getNetWork({
            url: e,
            success: function(a) {
                var e = a.data;
                1 == e.result && t.setData({
                    carousels_arr: e.data.carousels,
                    bannerObj: e.data.banner
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getCatagoryData: function() {
        var t = this, e = a.getNetAddresss(t.data.CATAGORY_URL);
        a._getNetWork({
            url: e,
            success: function(a) {
                var e = a.data;
                1 == e.result && t.setData({
                    catagory_arr: e.data
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getCustomizeHotelHead: function() {
        var t = this, e = "";
        try {
            var o = wx.getStorageSync("customizeHotelHead");
            o && (e = o);
        } catch (t) {}
        if (a._isTextEmpty(e)) {
            var i = a.getNetAddresss("plugin.hotel.frontend.hotel.get-hotel-info.get-custom-name");
            a._getNetWork({
                url: i,
                success: function(a) {
                    var e = a.data;
                    if (1 == e.result) {
                        t.setData({
                            PageNameList: e.data
                        }), wx.setNavigationBarTitle({
                            title: e.data.hotel_first_page ? e.data.hotel_first_page : ""
                        });
                        try {
                            wx.setStorageSync("customizeHotelHead", JSON.stringify(e.data));
                        } catch (t) {
                            console.log(t);
                        }
                    }
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        } else this.setData({
            PageNameList: JSON.parse(e)
        }), wx.setNavigationBarTitle({
            title: this.data.PageNameList.hotel_first_page
        });
    },
    imgHref: function(t) {
        var a = t.currentTarget.dataset.link;
        try {
            wx.navigateTo({
                url: a
            });
        } catch (t) {
            wx.showToast({
                title: "链接设置错误",
                icon: "none",
                duration: 2e3
            });
        }
    },
    routerGo: function(t) {
        wx.navigateTo({
            url: "/packageC/o2o/o2oLocation/o2oLocation?tag=hotel"
        });
    },
    gotoSearch: function() {
        wx.navigateTo({
            url: "/packageC/hotel/HotelSearch/HotelSearch?start=" + this.data.start_time + "&end=" + this.data.end_time
        });
    },
    gotoSearch2: function() {
        a._isTextEmpty(this.data.start_time) ? wx.showToast({
            title: "请选择入住时间",
            icon: "none",
            duration: 2e3
        }) : a._isTextEmpty(this.data.end_time) ? wx.showToast({
            title: "请选择离店时间",
            icon: "none",
            duration: 2e3
        }) : wx.navigateTo({
            url: "/packageC/hotel/HotelSearch/HotelSearch?start=" + this.data.start_time + "&end=" + this.data.end_time + "&price=" + this.data.value + "&star=" + this.data.star_value
        });
    },
    acceptTime: function(t) {
        var a = t.detail.type, e = t.detail.date;
        "离店" == a ? this.setData({
            end_time: e
        }) : "入住" == a && this.setData({
            start_time: e
        }), this.checkDate(a);
    },
    checkDate: function(t) {
        var e = new Date(this.data.start_time).getTime(), o = new Date(this.data.end_time).getTime();
        return a._isTextEmpty(this.data.start_time) ? (wx.showToast({
            title: "请先选择入住日期",
            icon: "none",
            duration: 2e3
        }), void this.setData({
            end_time: ""
        })) : e == o ? (wx.showToast({
            title: "入住和离店日期不能为同一天",
            icon: "none",
            duration: 2e3
        }), void this.setData({
            end_time: ""
        })) : e > o ? (wx.showToast({
            title: "离店日期需要大于入店日期",
            icon: "none",
            duration: 2e3
        }), void this.setData({
            end_time: ""
        })) : void ("离店" == t ? (this.getDays(this.data.start_time, this.data.end_time), 
        this.setData({
            show3: !1
        })) : "入住" == t && this.setData({
            show2: !1
        }));
    },
    closeHander: function(t) {
        var a = t.detail;
        "离店" == a ? this.setData({
            show3: !1
        }) : "入住" == a && this.setData({
            show2: !1
        });
    },
    getDays: function(t, a) {
        var e, o, i;
        e = t.split("-"), o = a.split("-");
        var n = new Date(e[0], e[1] - 1, e[2]), s = new Date(o[0], o[1] - 1, o[2]);
        i = parseInt(Math.abs(n - s) / 1e3 / 60 / 60 / 24), console.log(i), this.setData({
            night_day: i
        });
    },
    slidedrag: function(t) {
        var a = 10 * t.detail.value;
        this.setData({
            value: a
        });
    },
    slideChange: function(t) {
        var a = 10 * t.detail;
        this.setData({
            value: a
        });
    },
    starChoose: function(t) {
        var a = t.currentTarget.dataset.index, e = t.currentTarget.dataset.item;
        this.setData({
            current_index: a,
            star_value: e.value
        });
    },
    starSubmit: function(t) {
        var a = t.currentTarget.dataset.val;
        "reset" == a ? this.setData({
            current_index: 0,
            star_value: 2,
            value: 0,
            valueData: 0
        }) : "complete" == a && this.setData({
            show1: !1
        });
    },
    show1closebtn: function() {
        this.setData({
            show1: !1
        });
    },
    show2closebtn: function() {
        this.setData({
            show2: !1
        });
    },
    show3closebtn: function() {
        this.setData({
            show3: !1
        });
    },
    goCatagory: function(t) {
        var a = t.currentTarget.dataset.item;
        wx.navigateTo({
            url: "/packageC/hotel/HotelSearch/HotelSearch?category=" + a.id
        });
    },
    getMoreList: function() {
        var t = this;
        if (this.data.page != this.data.total_page) if (this.data.page >= this.data.total_page) t.setData({
            loading: !0,
            allLoaded: !0
        }); else {
            this.setData({
                page: this.data.page + 1
            });
            var e = a.getNetAddresss(t.data.HOTEL_LIST);
            e += "&lng=" + this.data.point.lng, e += "&lat=" + this.data.point.lat, e += "&city_name=" + this.data.city, 
            e += "&page=" + this.data.page, a._getNetWork({
                url: e,
                success: function(a) {
                    var e = a.data;
                    1 == e.result ? t.setData({
                        loading: !1,
                        allLoaded: !1,
                        hotel_arr: t.data.hotel_arr.concat(e.data.data)
                    }) : t.setData({
                        page: t.data.page - 1,
                        loading: !0,
                        allLoaded: !0,
                        isLoadMore: !1
                    });
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        }
    },
    gohome: function() {
        wx.reLaunch({
            url: "/packageG/index/index"
        });
    },
    goorderlist: function() {
        wx.navigateTo({
            url: "/packageA/member/myOrder_v2/myOrder_v2?status=0&orderType=hotel"
        });
    },
    gomember: function() {
        wx.reLaunch({
            url: "/packageG/member_v2/member_v2"
        });
    },
    showToolbar: function() {
        this.setData({
            toolbar: !this.data.toolbar
        });
    }
});